package com.example.demo.controller;

import com.example.demo.common.ResultVo;
import com.example.demo.entity.po.UserEntity;
import com.example.demo.service.UserAbstract;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
* @author auto
* @describe 自动生成
* @dateTime 12/26/2017 6:57 PM
*/
@RestController
@RequestMapping(value = "/mgr/user/")
public class UserController {

	@Autowired
	private UserAbstract userService;

	/**
	* 列表和分页数据
	* @param obj
	* @param request
	* @return 分页数据
	*/
	@RequestMapping(value = "/list",method = RequestMethod.POST)
	public ResultVo userList(Integer pageNum,Integer pageSize, UserEntity obj, HttpServletRequest request) {
			PageHelper.startPage(pageNum, pageSize);
		try {
		} catch (Exception e) {
		}
		{
			 //添加逻辑代码
		}
		ResultVo vo = new ResultVo();
		vo.setData(new PageInfo(userService.userMapper.select(obj)));
		return vo;
	}


	/**
	* 添加数据 add
	* @param obj
	* @param request
	*/
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public ResultVo userAdd( @RequestBody UserEntity obj, HttpServletRequest request) {
		ResultVo vo = new ResultVo();
		{
			 //添加逻辑代码
		}
		vo.setData(userService.userMapper.insert(obj));
		return vo;
	}



	/**
	* 数据更新 update
	* @param obj
	* @param request
	*/
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public ResultVo userUpdate( @RequestBody UserEntity obj, HttpServletRequest request) {
		ResultVo vo = new ResultVo();
		vo.setData(userService.userMapper.updateByPrimaryKey(obj));
		return vo;
	}

	/**
	* 根据参数查询 delete
	* @param id
	*/
	@RequestMapping(value = "/delete", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultVo userDelete(@RequestParam String id){
		ResultVo vo = new ResultVo();

		//TODO 请注意是否逻辑删除 
		//UserEntity obj = userService.userMapper.selectByPrimaryKey(id);
		{
			 //添加逻辑代码
		}
//		TODO 请注意是否逻辑删除
//		vo.setData(numberUserMgrService.numberUserMgrMapper.updateByPrimaryKeySelective(obj);
		vo.setData(userService.userMapper.delete(new UserEntity(){{setId(id);}}));	
		return vo;
	}

	/**
	* 修改前的对象查询 get
	* @param id
	* @param
	*/
	@RequestMapping(value = "/get", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultVo userget( @RequestParam Integer id){
		ResultVo vo = new ResultVo();
		vo.setData(userService.userMapper.selectByPrimaryKey(id));
		return vo;
	}

}